package com.qxzn.app.page.activity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.qxzn.app.page.BaseActivity;
import com.qxzn.app.page.R;
import com.qxzn.app.page.R2;
import com.qxzn.app.page.util.GlideBannerImageLoader;
import com.qxzn.app.util.AppUtil;
import com.qxzn.app.util.SharePreferenceUtil;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class GuideActivity extends BaseActivity {

    @BindView(R2.id.banner)
    Banner banner;
    @BindView(R2.id.tv_next)
    TextView tvNext;

    private List<Integer> images = new ArrayList<>();

    @Override
    protected int initLayout() {
        return R.layout.activity_guide;
    }

    @Override
    protected void initView() {
        SharePreferenceUtil.setFirstStart(this, false);
    }

    @Override
    protected void iniTitleBar() {
        title_bar.setVisibility(View.GONE);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        initBanner();
    }

    @Override
    protected void setFullScreen() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    private void initBanner() {
//        Integer[] images = {R.mipmap.guide1, R.mipmap.guide2, R.mipmap.guide3, R.mipmap.guide4};
        images.add(R.mipmap.guide1);
        images.add(R.mipmap.guide2);
        images.add(R.mipmap.guide3);
        images.add(R.mipmap.guide4);

//        images.add("http://www.szjietronics.com/repository/image/rQ-RueiJQICyBoAUsDzVSA.jpg?k=1552295730000");
//        images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1566536477789&di=36b3eb0ac0179376fd73193974b6620f&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F011c3e57b709cc0000018c1b334ee6.jpg%401280w_1l_2o_100sh.jpg");
//        images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1566536499925&di=5affc704779c0841293a9865f6fb50a4&imgtype=0&src=http%3A%2F%2Fpic.97uimg.com%2Fback_pic%2F20%2F16%2F04%2F10%2F43d6da2063c7492e2af4cbd072706c12.jpg%2521w1200");
        banner.setImages(images).isAutoPlay(false).setImageLoader(new GlideBannerImageLoader()).start();
        banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                AppUtil.showLog("---------------------" + position);
                if (position == images.size() - 1) {
                    tvNext.setVisibility(View.VISIBLE);
                } else {
                    tvNext.setVisibility(View.INVISIBLE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @OnClick({R2.id.tv_skip, R2.id.tv_next})
    public void onViewClicked(View view) {
        startActivity(new Intent().setComponent(new ComponentName(GuideActivity.this, "com.qxzn.app.personalcenter.activity.LoginByPwdActivity")));
        finish();
    }

}
